<template>
    <div>
        <h1>用户表</h1>
        <table class="table">
            <thead>
                <tr>
                    <td>
                        <input type="checkbox" >
                    </td>
                    <td>编号</td>
                    <td>名称</td>
                    <td>密码</td>
                </tr>
            </thead>
            <tbody>
                <tr v-for="item in data">
                    <td>
                        <input type="checkbox" :value="item.id" v-model="idlist">
                    </td>
                    <td>{{ item.id }}</td>
                    <td>{{ item.name }}</td>
                    <td>***</td>
                </tr>
            </tbody>
        </table>
        <input type="button" value="批量发放优惠券" @click="AddAll">
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { onMounted, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';


//选中的用户编号
const idlist=ref([])
const router=useRouter();
const route=useRoute();

onMounted(()=>{
    Getdata();
})
const data=ref([ {
    "id": 1,
    "name": "admin",
    "password": "202cb962ac59075b964b07152d234b70"
  }])
const Getdata=()=>{
    axios.get("https://localhost:7275/api/Member/GetMembers").then(res=>{
        data.value=res.data;
    })
}

//选择用户发券
const AddAll=()=>{
    let mid=idlist.value.toString();
    let cid=route.query.idstring

    axios.get("https://localhost:7275/api/CouponsToMember/Add",{params:{midstring:mid,cidstring:cid}}).then(res=>{
        if(res.data>0){
            alert('发放成功')
            router.push({path: '/Show'});
        }
        else{
            alert('添加失败');
        }
    })
}
</script>

<style scoped>

</style>